var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0});
var i = e("ADAssetsManager"),
    a = (function () {
        function e() {
            (this._currViewName = ""),
                (this._nativePatchDisplayState = !1),
                (this._nativePatchDisplayTag = !0),
                (this._isLoadComplete = !1),
                (this._loadAutoShow = !1),
                (this._isConsume = !1),
                (this._onLoadCallbackRef = null),
                (this._onResizeCallbackRef = null),
                (this._onErrorCallbackRef = null),
                (this._nativePatch = null),
                (this._adData = null);
        }
        return (
            (e.prototype.init = function () {
                console.log("nativePatch init"),
                    (this._onLoadCallbackRef = this.onNativePatchLoad.bind(this)),
                    (this._onErrorCallbackRef = this.onNativePatchError.bind(this)),
                    this.createNativePatch(!1);
            }),
            (e.prototype.createNativePatchNode = function () {
                cc.isValid(this._nativePatch) && (this._nativePatch.destroy(), (this._nativePatch = null));
                var e = i.adAssetsMap.prefabs.NativePatch_Default;
                this._currViewName && (e = i.adAssetsMap.prefabs[this._currViewName]),
                    (this._nativePatch = i.default.instance.createNodeByPreloading(e)),
                    (this._nativePatch.zIndex = cc.macro.MAX_ZINDEX),
                    this._nativePatch
                        .getChildByName("content")
                        .getChildByName("btn_look")
                        .on("click", this.onClickAD, this),
                    this._nativePatch
                        .getChildByName("content")
                        .getChildByName("ad_img")
                        .on("click", this.onClickAD, this);
            }),
            (e.prototype.destroyNativePatchNode = function () {
                cc.isValid(this._nativePatch) && (this._nativePatch.destroy(), (this._nativePatch = null));
            }),
            (e.prototype.showNativePatch = function (e, t) {
                console.log("showNativePatch", e),
                    (this._currViewName = e),
                    (this._showCallback = t),
                    (this._nativePatchDisplayState = !0);
            }),
            (e.prototype.hideNativePatch = function (e) {
                console.log("hideNativePatch", e), (this._nativePatchDisplayState = !1), (this._showCallback = null);
            }),
            (e.prototype.setNativePatchDisplayTag = function (e) {
                if ((console.log("setNativePatchDisplayTag", e), this._nativePatchDisplayTag != e))
                    if (((this._nativePatchDisplayTag = e), e))
                        this._nativePatchDisplayState && this.showNativePatch(this._currViewName, this._showCallback);
                    else {
                        var t = this._nativePatchDisplayState;
                        this.hideNativePatch(!1), (this._nativePatchDisplayState = t);
                    }
            }),
            (e.prototype.destroyNativePatch = function () {
                console.log("destoryNativePatch"),
                    (this._currViewName = ""),
                    (this._showCallback = null),
                    (this._nativePatchDisplayState = !1),
                    (this._isLoadComplete = !1),
                    (this._loadAutoShow = !1),
                    (this._isConsume = !1),
                    this.destroyNativePatchNode();
            }),
            (e.prototype.setAdData = function (e) {
                var t = this;
                console.log("setAdData", e),
                    cc.isValid(this._nativePatch) &&
                        e &&
                        cc.loader.load({url: e, type: "png"}, function (e, o) {
                            if (e) console.error("原生patch img加载失败");
                            else {
                                var n = new cc.SpriteFrame(o);
                                n
                                    ? (t._nativePatch
                                          .getChildByName("content")
                                          .getChildByName("ad_img")
                                          .getComponent(cc.Sprite).spriteFrame = n)
                                    : console.error("原生patch img加载失败");
                            }
                        });
            }),
            e
        );
    })();
n.default = a;
